package _0808;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[] animal = new Animal[5];
        animal[0] = new Dog("小花", 4, "花色");
        animal[1] = new Chick("小鸡", 1, "黄色");
        animal[2] = new Fish("小鱼", 2, "蓝色");
        animal[3] = new Dog("小黑", 3, "黑色");
        animal[4] = new Fish("小鱼", 2, "紫色");
        for (int i = 0; i < animal.length; i++) {
            System.out.println(animal[i].name);
            animal[i].eat();
            animal[i].drink();

            if (animal[i] instanceof Dog) {
                Dog dg = (Dog) animal[i];
                dg.lookHome();
            }
            if (animal[i] instanceof Chick) {
                Chick c = (Chick) animal[i];
                c.layEggs();
            }
            if (animal[i] instanceof Swim) {
                Swim s = (Swim) animal[i];
                s.swim();

            }
        }
    }
}
